#pragma once

#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include<ctime>
#include<functional>  //function
#include<vector>

using std::string;
using std::cin;
using std::cout;
using std::endl;
using std::vector;

//等价于 typedef Task_fun = std::function<void()>;
typedef std::function<void()> Task_fun;


void Download()
{
    std::cout << "我是一个下载任务"
              << " 处理者: " << getpid() << std::endl;
}

void PrintLog()
{
    std::cout << "我是一个打印日志的任务"
              << " 处理者: " << getpid() << std::endl;
}

void PushVideoStream()
{
    std::cout << "这是一个推送视频流的任务"<< " 处理者: " << getpid() << std::endl;
}


class Init
{
    public:
    std::vector<Task_fun> Task;
    std::vector<string> TaskName;

    const static int _DownLoad=0;
    const static int _PrintLog=1;
    const static int _PushVoideoStream=2;
    Init()
    {
        TaskName.push_back("download");
        TaskName.push_back("printlog");
        TaskName.push_back("pushvideo");
        Task.push_back(Download);
        Task.push_back(PrintLog);
        Task.push_back(PushVideoStream);
        srand(time(nullptr)^getpid());
    }

    bool CheckCode(int code)
    {
        if(code>=0&&code<Task.size())
        return true;
        return false;
    }

    void RunTask(int code)  //执行任务
    {
        Task[code]();  
    }

    int SendTask()
    {
        return rand()%Task.size();
    }

    string Todesc(int code)
    {
        if(code>=0&&code<Task.size())
        return TaskName[code];
        return "UnKnow";
    }
};

Init init;